# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# It's necessary to set this because some environments don't link sh -> bash.
SHELL := /bin/bash

ARCH                        = $(shell uname -m)
DOCKER_REGISTRY            ?= docker.io
IMAGE_NAME                 ?= wheels
IMAGE_PREFIX               ?= starlingx4arm
IMAGE_TAG                  ?= 3.0-${ARCH}
LATEST_TAG                 ?= latest-${ARCH}
BUILD_TAG                  ?= dev-${LATEST_TAG}
KUBE_VERSION               ?= v1.16.2

IMAGE := ${DOCKER_REGISTRY}/${IMAGE_PREFIX}/${IMAGE_NAME}:${IMAGE_TAG}	
LATEST_IMAGE := ${DOCKER_REGISTRY}/${IMAGE_PREFIX}/${IMAGE_NAME}:${LATEST_TAG}	
BUILD_IMAGE := ${DOCKER_REGISTRY}/${IMAGE_PREFIX}/${IMAGE_NAME}:${BUILD_TAG}

all: image push
.PHONY: all

push:
	docker push $(BUILD_IMAGE)
	docker push $(IMAGE)
	docker tag $(IMAGE) ${LATEST_IMAGE}
	docker push ${LATEST_IMAGE}
.PHONY: push

image:
	docker build --network host \
	--build-arg LATEST_IMAGE=$(LATEST_IMAGE) \
	-t $(BUILD_IMAGE) . -f build.Dockerfile
	docker build \
	--network host \
	--build-arg BUILD_IMAGE=$(BUILD_IMAGE) \
	-t $(IMAGE) . -f Dockerfile
	docker tag $(IMAGE) ${LATEST_IMAGE}
.PHONY: image